package com.wenbing.miio.core;

import com.wenbing.miio.core.exception.NetworkLayerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.time.Clock;

/**
 * 网络协议栈
 * @author wen bing
 * @projectName: miio
 * @package: com.wenbing.miio.core
 * @className: NetworkStack
 * @date 2024/09/19 14:25
 **/
public class SimpleNetworkStack extends NetworkStackLayer implements NetworkStack {

    /**
     * 时钟
     */
    private Clock clock;

    /**
     * 硬件配置
     */
    private Device.HardwareConfiguration configuration;

    public SimpleNetworkStack(Device.HardwareConfiguration configuration, Clock clock) {
        super();
        assert configuration != null && clock != null;
        this.configuration = configuration;
        this.clock = clock;
    }

    @Override
    public Clock getClock() {
        return clock;
    }

    @Override
    public Device.HardwareConfiguration getConfiguration() {
        return configuration;
    }


    @Override
    protected boolean inboundCondition(NetworkLayerContext context, ByteBuffer packingData) {
        return true;
    }

    @Override
    protected boolean outboundCondition(NetworkLayerContext context, ByteBuffer packingData) {
        return true;
    }

    @Override
    protected ByteBuffer unpacking(NetworkLayerContext context, ByteBuffer packingData) throws IOException, NetworkLayerException {
        return packingData;
    }

    @Override
    protected ByteBuffer packing(NetworkLayerContext context, ByteBuffer packingData) throws IOException, NetworkLayerException {
        return packingData;
    }
}
